package com.atguigu.lease.web.app.mapper;

import com.atguigu.lease.model.entity.LeaseTerm;
import com.atguigu.lease.model.entity.PaymentType;
import com.atguigu.lease.model.entity.RoomInfo;
import com.atguigu.lease.web.app.vo.room.RoomItemVo;
import com.atguigu.lease.web.app.vo.room.RoomQueryVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;

/**
* @author liubo
* @description 针对表【room_info(房间信息表)】的数据库操作Mapper
* @createDate 2023-07-26 11:12:39
* @Entity com.atguigu.lease.model.entity.RoomInfo
*/
public interface RoomInfoMapper extends BaseMapper<RoomInfo> {

    IPage<RoomItemVo> pageItem(Page<RoomItemVo> page, RoomQueryVo queryVo);

    IPage<RoomItemVo> pageItemByApertmentId(Page<RoomItemVo> page, Long id);

    /**
     * 查询最小租金
     * @param id
     * @return
     */
    @Select("select min(rent) from room_info where apartment_id = #{id}")
    BigDecimal selectMinRentByApartmentId(Long id);

    @Select("select id, name, pay_month_count, additional_info from payment_type where is_deleted = 0 " +
            "and id in (select payment_type_id from room_payment_type where room_id = #{id})")
    List<PaymentType> selectPaymentTypeList(Long id);

    @Select("select id, month_count, unit from lease_term where is_deleted = 0 " +
            "and id in (select lease_term_id from room_lease_term where room_id = #{id})")
    List<LeaseTerm> getLeaseTermListByRoomId(Long id);
}